package com.atguigu.srb.sms.controller;

import com.atguigu.srb.core.exception.Assert;
import com.atguigu.srb.core.result.R;
import com.atguigu.srb.core.result.ResponseEnum;
import com.atguigu.srb.sms.clientfeign.CoreUserInfoClientFeign;
import com.atguigu.srb.sms.service.SmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/sms")
@Api(tags = "短信管理服务")
//@CrossOrigin //跨域
@Slf4j
public class SmsController {

    @Autowired
    SmsService smsService;
    @Resource
    CoreUserInfoClientFeign coreUserInfoClientFeign;

    @GetMapping("send/{mobile}")
    @ApiOperation(value = "发送短信验证码")
    public R send(@PathVariable("mobile")
                  @ApiParam(value = "输入手机号11位", required = true)
                          String mobile) {
        // 验证手机号是否被注册
        Boolean res = coreUserInfoClientFeign.checkMobile(mobile);
        log.info("--------验证手机号是否被注册-------->>> res: " +res);
        Assert.isTrue(!res, ResponseEnum.MOBILE_EXIST_ERROR);
        smsService.sendMsg(mobile);
        return R.ok();
    }


}
